#include "oxford-full-list-updater.h"

using namespace Oxford;

FullListUpdater::FullListUpdater() : QObject(), QRunnable()
{
    databaseManager = new Core::DatabaseManager("Oxford");
}

FullListUpdater::~FullListUpdater()
{
    delete databaseManager;
}

void FullListUpdater::run()
{
    emit updateStarted();
    emit logMessage("Oxford full word list update started");

    QStringList allWords;

    try
    {
        for (char letter = 'a'; letter <= 'z'; letter++)
        {
            QStringList wordRanges = oxfordLoader.loadWordRangesForLetter(letter);

            foreach(const QString& wordRangeLink, wordRanges)
            {
                QStringList words = oxfordLoader.loadWordsInRange(letter, wordRangeLink);

                allWords << words;
            }
        }

        databaseManager->storeList("All", allWords);
    }
    catch (...)
    {

    }

    emit updateFinished();
    emit logMessage("Oxford full word list update finished");
}
